import { IGetRoleListParams, IPermission, IRoleInfo, IRoleItem } from '@/types/roles'
import request from '@/utils/request'
import { AxiosPromise } from 'axios'
/**
 * 角色列表
 * @param params
 * @returns
 */
function getRoleList(params?: IGetRoleListParams): AxiosPromise {
  return request({
    url: '/roles/list',
    method: 'get',
    params
  })
}

/**
 * 创建角色
 * @param data
 * @returns
 */
function createRole(data: IRoleInfo): AxiosPromise {
  return request({
    url: '/roles/create',
    method: 'post',
    data
  })
}

/**
 * 编辑角色
 * @param data
 * @returns
 */
function editRole(data: IRoleItem): AxiosPromise {
  return request({
    url: '/roles/edit',
    method: 'post',
    data
  })
}

/**
 * 删除角色
 * @param id
 * @returns
 */
function deleteRole(id: string): AxiosPromise {
  return request({
    url: '/roles/delete',
    method: 'post',
    data: { _id: id }
  })
}

/**
 * 更新权限设置
 * @param data
 * @returns
 */
function updatePermission(data: IPermission): AxiosPromise {
  return request({
    url: '/roles/update/permission',
    method: 'post',
    data
  })
}

/**
 * 获取所有角色列表
 * @returns
 */
function getAllRoleList() {
  return request({
    url: '/roles/allList',
    method: 'get'
  })
}

export { getRoleList, createRole, editRole, deleteRole, updatePermission, getAllRoleList }
